package com.anolesoft.yr.mbus.prod.model.crtl;

import com.anolesoft.common.core.web.domain.AjaxResult;
import com.anolesoft.yr.mbus.prod.model.dto.*;
import com.anolesoft.yr.mbus.prod.model.service.ProdServiceValueService;
import com.anolesoft.yr.mbus.prod.model.vo.ProdServiceValueQueryVO;
import com.google.gson.Gson;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

import java.util.*;

@Controller
@CrossOrigin
@RequestMapping(value = "/prodServiceValue")
public class ProdServiceValueController {

    @Autowired
    ProdServiceValueService prodServiceValueService;

    //根据主键查询产品服务项参数名称
    @RequestMapping(value = "/queryServiceValueValue", method = RequestMethod.POST)
    @ResponseBody
    public String queryProdServiceName(String objuid) throws Exception {
        List<ProdServiceValueQueryVO> prodServiceValueQueryVOList = prodServiceValueService.queryProdServiceValueValue(objuid);

        String jsons = "";
        jsons += "[";
        if (prodServiceValueQueryVOList.size() > 0) {
            for (int i = 0; i < prodServiceValueQueryVOList.size(); i++) {
                ProdServiceValueQueryVO prodServiceValueQueryVO = (ProdServiceValueQueryVO) prodServiceValueQueryVOList.get(i);
                jsons += new Gson().toJson(prodServiceValueQueryVO);
                if (i < (prodServiceValueQueryVOList.size() - 1)) {
                    jsons += ",";
                }
            }
        }
        jsons += "]";

        return jsons;
    }

    //根据主键查询产品服务项参数信息
    @RequestMapping(value = "/queryServiceValueByUid", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult queryServiceValueByUid(@RequestBody ProdServiceValueQueryDTO prodServiceValueQueryDTO) throws Exception {
        Map<String, Object> maps = prodServiceValueService.queryProdServiceValueByUid(prodServiceValueQueryDTO.getObjuid());
        ProdServiceValueQueryVO prodServiceValueQueryVO = (ProdServiceValueQueryVO) maps.get("prodServiceValueQueryVO");

        String jsons = "";
        if (prodServiceValueQueryVO != null) {
            jsons += "[";
            jsons += new Gson().toJson(prodServiceValueQueryVO);
            jsons += "]";
        }

        return new AjaxResult(200, "SUCCESS", jsons);
    }

    //查询服务项参数
    @RequestMapping(value = "/queryProdServiceValue2", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult queryProdServiceValue2(String serviceName) throws Exception {
        List<ProdServiceValueQueryVO> prodServiceValueQueryVOList = prodServiceValueService.queryProdServiceValue2(serviceName);

        String jsons = "";
        jsons += "[";
        if (prodServiceValueQueryVOList.size() > 0) {
            for (int i = 0; i < prodServiceValueQueryVOList.size(); i++) {
                ProdServiceValueQueryVO prodServiceValueQueryVO = (ProdServiceValueQueryVO) prodServiceValueQueryVOList.get(i);
                jsons += new Gson().toJson(prodServiceValueQueryVO);
                if (i < (prodServiceValueQueryVOList.size() - 1)) {
                    jsons += ",";
                }
            }
        }
        jsons += "]";

        return new AjaxResult(200, "SUCCESS", jsons);
    }

    //查询询盘回访服务报价单中服务级别
    @RequestMapping(value = "/queryProdServiceValue3", method = RequestMethod.POST)
    @ResponseBody
    public AjaxResult queryProdServiceValue3(String serviceName) throws Exception {
        List<ProdServiceValueQueryVO> prodServiceValueQueryVOList = prodServiceValueService.queryProdServiceValue3();

        String jsons = "";
        jsons += "[";
        if (prodServiceValueQueryVOList.size() > 0) {
            for (int i = 0; i < prodServiceValueQueryVOList.size(); i++) {
                ProdServiceValueQueryVO prodServiceValueQueryVO = (ProdServiceValueQueryVO) prodServiceValueQueryVOList.get(i);
                jsons += new Gson().toJson(prodServiceValueQueryVO);
                if (i < (prodServiceValueQueryVOList.size() - 1)) {
                    jsons += ",";
                }
            }
        }
        jsons += "]";

        return new AjaxResult(200, "SUCCESS", jsons);
    }

}
